/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package DAO;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;
import java.util.ArrayList;
import java.util.Map;
import java.lang.*;

/**
 *
 * @author admin-pc
 */
public class BookDAOImpl implements BookDAO{

    BookDAOImpl() {
        
    }

   
    public List findById(Map bookMap) {
        Connection conn = null;
        PreparedStatement pstmt = null;
        ResultSet rs = null;
        List bookList = new ArrayList();
        BookTO tmpBookTO = null;
        try{
            conn = DBUtil.getConnection();
            pstmt = conn.prepareStatement(FIND_BY_ID); 
            pstmt.setDouble(1, Double.valueOf((String)bookMap.get("")));
            pstmt.setDouble(2, Double.valueOf((String)bookMap.get("")));
            rs = pstmt.executeQuery();
            int tmpBookId = 0;
            String tmpBookTitle = "";
            String tmpBookStatus = "";
            while(rs.next()){
                tmpBookId = rs.getInt("BOOKID");
                tmpBookTitle =rs.getString("TITLE");
                tmpBookStatus = rs.getString("STATUS");
                tmpBookTO= new BookTO(tmpBookId,tmpBookTitle,tmpBookStatus);
                bookList.add(tmpBookTO);                
            }             
        }
        catch(SQLException  sqle){
            throw new  SQLException(sqle);      //В примере было throw new DBException(sqle);  
        }
        finally{
            try{
                if(rs != null){
                    rs.close();
                }
            }
            catch(SQLException sqle){
                throw new SQLException(sqle);   //В примере было throw new DBException(sqle);  
            }
            try{
                if(pstmt != null){
                    pstmt.close();
                }
            }
            catch(SQLException sqle){
                throw new SQLException(sqle);  //В примере было throw new DBException(sqle);  
            }
            try{
                if(conn != null){
                    conn.close();
                }
            }
            catch(SQLException sqle){
                throw new SQLException(sqle);   //В примере было throw new DBException(sqle);  
            }
        }
        return bookList;
        
    }
   
    
    
}
